package com.atguigu.tingshu.search.config;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Data
@ConfigurationProperties(prefix = "threadpool")
@Configuration
public class ThreadPoolConfiguration {
    private int coreSize ;
    private int maxSize ;
    private int keepAliveTime ;
    private int workQueueSize ;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(coreSize ,
                maxSize , keepAliveTime , TimeUnit.SECONDS , new ArrayBlockingQueue<>(workQueueSize) ,
                Executors.defaultThreadFactory() ,  new ThreadPoolExecutor.AbortPolicy()) ;
        return threadPoolExecutor ;
    }
}
